#include <cstdio>
#include <cstdlib>
#define N 8

short is_safe(int row,int col,int n,int arr[][N])
{
    for (int i = 0;i < n;i++)   
    {
        if (arr[i][col]== 1)   return 0;
    }
    for (int i = row-1,j = col-1;i >= 0&&j >= 0;i--,j--)
    {
        if (arr[i][j] == 1)     return 0;
    }
    for (int i = row-1,j = col+1;i >= 0&&j < n;i--,j++)
    {
        if (arr[i][j] == 1)     return 0;
    }
    return 1;
}

void solve(int row,int n,int *pcount,int arr[][N])
{
    if (row == n)
    {
        (*pcount)++;
        return ;
    }

    for (int i = 0;i < n;i++)
    {
        if (is_safe(row,i,n,arr))
        {
            arr[row][i] = 1;
            solve(row+1,n,pcount,arr);
            //只要row!= n就是没成功
            // 如果下一次没成功，就回来拿掉上一个皇后
            arr[row][i] = 0;
        }
    }
}

int Nqueen(int n ) {
    int count = 0;
    int *pcount = &count;
    int arr[N][N] = {0};
    solve(0,N,pcount,arr);

    return count;
}

int main()
{
    printf("%d\n",Nqueen(N));
    return 0;
}